//
//  NSObject+KVODefender.m
//  CommonTool
//
//  Created by Name i on 2022/4/13.
//

#import "NSObject+KVCDefender.h"
#import "NNDefender.h"

@implementation NSObject (KVCDefender)

+ (void)kvcExchangeMethod {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [NSObject tnSwizzlingInstanceMethod:@selector(setValue:forKey:)
                                 withMethod:@selector(safe_setValue:forKey:)
                                  withClass:[NSObject class]];

    });
}

- (void)safe_setValue:(id)value forKey:(NSString *)key {
    @try {
        [self safe_setValue:value forKey:key];
    } @catch (NSException *exception) {
        [NNDefender crashWithException:exception defaultToDo:NNDefenderDefaultIgnore];
    } @finally {
    }
}

@end
